#include "airport.h"
#include <string>

using namespace std;
using namespace aviation;

//Constructors

Airport::Airport()
{
	m_airportString = "AAA";
}

aviation::Airport::Airport(const string& fcgString)
{
	//We only allow an airport code of length 3
	if(fcgString.length() < 3) throw exception("Attempted to instantiate an Airport object with a string that is too short.");
	if(fcgString.length() > 3) throw exception("Attempted to instantiate an Airport object with a string that is too long.");

	char s1 = fcgString[0];
	char s2 = fcgString[1];
	char s3 = fcgString[2];

	//Check that all the characters are uppercase
	int lowercaseOffset = 32;

	if(!(s1 >= 'A' && s1 <= 'Z')) 
	{
		s1 -= lowercaseOffset;
		if(!(s1 >= 'A' && s1 <= 'Z')) 
			throw std::exception("Attempted to instantiate an Airport object with a string that has a first character that is not a capital letter.");
	}

	if(!(s2 >= 'A' && s2 <= 'Z')) 
	{
		s2 -= lowercaseOffset;
		if(!(s2 >= 'A' && s2 <= 'Z')) 
			throw std::exception("Attempted to instantiate an Airport object with a string that has a second character that is not a capital letter.");
	}

	if(!(s3 >= 'A' && s3 <= 'Z')) 
	{
		s3 -= lowercaseOffset;
		if(!(s3 >= 'A' && s3 <= 'Z')) 
			throw std::exception("Attempted to instantiate an Airport object with a string that has a third character that is not a capital letter.");
	}

	//returns a string
	string tmp;
	tmp += s1;
	tmp += s2;
	tmp += s3;
	m_airportString = tmp;
}

Airport::Airport(const Airport& other)
{
	*this = other;
}

Airport::~Airport()
{
}

Airport& Airport::operator=(const Airport& other)
{
	m_airportString = other.m_airportString;
	return *this;
}

const bool Airport::operator==(const Airport& other) const
{
	return m_airportString == other.m_airportString;
}

const bool Airport::operator!=(const Airport& other) const
{
	return !(*this == other);
}

const string Airport::AsString() const
{
	return m_airportString;
}